/*
 * GBBMGMTView.java
 */

package gbbmgmt;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
//import java.awt.event.ActionEvent;
//import java.awt.event.ActionListener;
//import javax.swing.Timer;
//import javax.swing.Icon;
//import javax.swing.JDialog;
//import javax.swing.JFrame;
//import javax.swing.plaf.metal.MetalLookAndFeel;
//import javax.swing.plaf.metal.DefaultMetalTheme;
//import javax.swing.UIManager;
//import javax.swing.UnsupportedLookAndFeelException;

//import java.sql.*;
//import java.util.*;
//import java.io.*;
//import javax.swing.UIManager;
//import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.UIManager.LookAndFeelInfo;
//import java.lang.Object;
//import java.util.TimerTask;
//import java.awt.event.WindowAdapter;
//import java.awt.event.WindowEvent;
//import java.awt.Dimension;
//import java.awt.Toolkit;
//import javax.swing.tree.*;
//import javax.swing.JOptionPane;
//import javax.swing.JButton;
//import javax.swing.ImageIcon;
//import java.awt.Container;
//import javax.swing.JInternalFrame;
import java.net.MalformedURLException;
import java.io.*;
import java.net.URL;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import java.io.File;
import javax.xml.parsers.ParserConfigurationException;
//import org.xml.sax.SAXParseException;
import org.xml.sax.SAXException;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerException;





/**
 * The application's main frame.
 */
public class GBBMGMTView extends FrameView {

    //Sets weather or not the login screen will be displayed.
    public boolean loginscrn = true;

    public JDialog dialog;

    public JButton[] favButtons = new JButton[100];

    public Component tcomp = null;

    public int favbtnsize = 0;

    public class PopupListener extends MouseAdapter{
        @Override
        public void mousePressed(java.awt.event.MouseEvent e){
            doPopRemove(e);
        }
        @Override
        public void mouseReleased(java.awt.event.MouseEvent e){
            doPopRemove(e);
        }
    }


    public GBBMGMTView(SingleFrameApplication app) {
        super(app);

        try {
            //UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
            for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (UnsupportedLookAndFeelException e) {
            // handle exception
        } catch (ClassNotFoundException e) {
            // handle exception
        } catch (InstantiationException e) {
            // handle exception
        } catch (IllegalAccessException e) {
            // handle exception
        }

        //Try to disable the close button on the window.
        //CMenu* mnu = this->GetSystemMenu(false);

        initComponents();

        ConfigOps r = new ConfigOps();
        r.ReadConfig();

        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

        //Show Login Dialog.
        if(loginscrn == true){
            if(dialog == null){
                JFrame mainFrame = GBBMGMTApp.getApplication().getMainFrame();
                dialog = new LoginDialog(mainFrame, true);
                int w = dialog.getSize().width;
                int h = dialog.getSize().height;
                int x = (dim.width-w)/2;
                int y = (dim.height-h)/2;
                dialog.setLocation(x,y);
                dialog.setVisible(true);
            }
        } else {
            Global.userLevel = 0;
        }

        //Check if the logged in variable is set, if so continue on, if not exit.
        
        //Global.userLevel = 0;
        

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }

        });

        if(loginscrn == true){
            if(Global.isLoggedIn == false){
                jButtonExit.doClick();
            }
        }

        //Add popup menu to tree view.
        JMenuItem addMenuItem = new JMenuItem("Add to Favorites");
        addMenuItem.setMnemonic('a');
        jPopupMenu1.add(addMenuItem);
        addMenuItem.addActionListener(
                new ActionListener(){
                    public void actionPerformed(ActionEvent e){
                        AddFavorite();
                    }
                }
        );

        //Add popup menu item to favorites for removing files.
        JMenuItem rmvMenuItem = new JMenuItem("Remove From Favorites");
        rmvMenuItem.setMnemonic('r');
        jPopupMenu2.add(rmvMenuItem);
        rmvMenuItem.addActionListener(
            new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    RemoveFavorite(tcomp.getName());
                }
            }
        );

        //Remove the close button on the dialog.

        //Add stuff to the desktop frame
        AddDesktop();
    }

    private void AddDesktop(){
        //Open preferences.xml
        URL xmlURL = null;
        try{
            xmlURL = new URL("File:///" + System.getProperty("user.dir") + File.separator + "preferences.xml");
        } catch (MalformedURLException me){
            //me.printStackTrace();
        }
        File xmlFile = new File(xmlURL.getFile());

        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(3,3,3,3);
        gbc.weightx = 1.0;
        gbc.anchor = GridBagConstraints.CENTER;

        


        //Parse XML file.
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        try{
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(xmlFile);
            NodeList list = doc.getElementsByTagName("FAV");
            favbtnsize = list.getLength();
            for (int i=0; i<list.getLength(); i++){
                //Get Node
                Node fstNode = list.item(i);
                //Go through each node in XML file labeled FAV
                if(fstNode.getNodeType() == Node.ELEMENT_NODE){
                    //Grab Element
                    Element element = (Element)fstNode;
                    //Find Text Element.
                    NodeList txtElement = element.getElementsByTagName("TEXT");
                    Element txte = (Element) txtElement.item(0);
                    NodeList txt = txte.getChildNodes();
                    String bName = ((Node)txt.item(0)).getNodeValue().toString();
                    //Find Icon Element.
                    NodeList icnElement = element.getElementsByTagName("ICON");
                    Element icne = (Element) icnElement.item(0);
                    NodeList icn = icne.getChildNodes();
                    String iName = ((Node)icn.item(0)).getNodeValue().toString();

                    //Build the button.
                    favButtons[i] = new JButton(bName);
                    URL iconURL = null;
                    try{
                        iconURL = new URL("File:///" + System.getProperty("user.dir") + File.separator + "icons" +File.separator + iName);
                    } catch (MalformedURLException me){
                        //me.printStackTrace();
                    }
                    ImageIcon icon = new ImageIcon(iconURL);

                    //Setup Buttons for favorites.
                    favButtons[i].setIcon(icon);
                    favButtons[i].setName(bName);
                    favButtons[i].setVerticalTextPosition(SwingConstants.BOTTOM);
                    favButtons[i].setHorizontalTextPosition(SwingConstants.CENTER);
                    favButtons[i].setActionCommand(bName);
                    favButtons[i].addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent e){
                            String cmd = e.getActionCommand();
                            Actions.CallFunction(cmd);
                        }
                    });
                    MouseListener popupListener = new PopupListener();
                    favButtons[i].addMouseListener(popupListener);

                    //Algorithm to create rows of buttons.
                    if((((i+1) % 3) == 0)){
                        gbc.gridwidth = GridBagConstraints.REMAINDER;
                    } else {
                        gbc.gridwidth = 1;
                    }
                    jPanelFavs.add(favButtons[i],gbc);
                }
            }

            //Setup maximum button variables.
            Dimension dim = new Dimension();
            int mbx = 150;
            int mby = 50;
            int panelx = mbx*4;
            int panely = mby*3;
            jInternalFrameFavs.setSize(panelx,panely);
            //Set all buttons to be the same size.
            for (int i=0; i<favbtnsize; i++){
                favButtons[i].setSize(mbx,mby);
                favButtons[i].setPreferredSize(new Dimension(mbx,mby));
            }

        } catch ( ParserConfigurationException e) {
            //e.printStackTrace();
        } catch ( SAXException e) {
            //e.printStackTrace();
        } catch ( IOException e) {
            //e.printStackTrace();
        }
    }

    public void AddFavorite(){
        //Check that node is valie.
        Object node = jTreeGBB.getLastSelectedPathComponent();
        if (node == null) return; //Return if nothing is selected.
        //Open preferences.xml
        URL xmlURL = null;
        try{
            xmlURL = new URL("File:///" + System.getProperty("user.dir") + File.separator + "preferences.xml");
        } catch (MalformedURLException me){
            //me.printStackTrace();
        }
        File xmlFile = new File(xmlURL.getFile());
         //Parse XML file.
        try{
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(xmlFile);
            //Get the root element.
            Node favorites = doc.getFirstChild();
            //Get the FAV elements.
            Element newFav = doc.createElement("FAV");
            Element newTxt = doc.createElement("TEXT");
            Element newIcn = doc.createElement("ICON");

            //Append text and icon to new fav.
            newTxt.appendChild(doc.createTextNode(node.toString()));
            newIcn.appendChild(doc.createTextNode(Actions.ReturnIcon(node.toString())));
            newFav.appendChild(newTxt);
            newFav.appendChild(newIcn);
            favorites.appendChild(newFav);

            //Write the content to an xml file.
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            Transformer transformer = transformerFactory.newTransformer();
            DOMSource source = new DOMSource(doc);
            StreamResult result =  new StreamResult(new File(xmlURL.getFile()));
            transformer.transform(source, result);

        } catch ( ParserConfigurationException e) {
            //e.printStackTrace();
        } catch ( SAXException e) {
            //e.printStackTrace();
        } catch ( IOException e) {
            //e.printStackTrace();
        } catch(TransformerException tfe){
            //tfe.printStackTrace();
        }

        for (int i=0; i<favbtnsize; i++){
            jPanelFavs.remove(favButtons[i]);
        }
        favbtnsize = 0;
        AddDesktop();
        jPanelFavs.repaint();
        jPanelFavs.setVisible(false);
        jPanelFavs.setVisible(true);
    }

    public void RemoveFavorite(String name){
        //Open preferences.xml
        URL xmlURL = null;
        try{
            xmlURL = new URL("File:///" + System.getProperty("user.dir") + File.separator + "preferences.xml");
        } catch (MalformedURLException me){
            //me.printStackTrace();
        }
        File xmlFile = new File(xmlURL.getFile());
        //Parse XML file.
        try{
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(xmlFile);

            NodeList list = doc.getElementsByTagName("FAV");
            for (int i=0; i<list.getLength(); i++){
                //Get Node
                Node fstNode = list.item(i);
                //Go through each node in XML file labeled FAV
                if(fstNode.getNodeType() == Node.ELEMENT_NODE){
                    //Grab Element
                    Element element = (Element)fstNode;
                    //Find Text Element.
                    NodeList txtElement = element.getElementsByTagName("TEXT");
                    Element txte = (Element) txtElement.item(0);
                    NodeList txt = txte.getChildNodes();
                    String bName = ((Node)txt.item(0)).getNodeValue().toString();
                    if(bName.equals(name)){
                        int response = JOptionPane.showConfirmDialog(null,
                            "This will modify favorites, continue?",
                            "Warning",JOptionPane.WARNING_MESSAGE);
                        list.item(i).getParentNode().removeChild(list.item(i));
                    }
                }
            }

            doc.normalize();

            //Write the content to an xml file.
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            Transformer transformer = transformerFactory.newTransformer();
            DOMSource source = new DOMSource(doc);
            StreamResult result =  new StreamResult(new File(xmlURL.getFile()));
            transformer.transform(source, result);

        } catch ( ParserConfigurationException e) {
            //e.printStackTrace();
        } catch ( SAXException e) {
            //e.printStackTrace();
        } catch ( IOException e) {
            //e.printStackTrace();
        } catch(TransformerException tfe){
            //tfe.printStackTrace();
        }

        for (int i=0; i<favbtnsize; i++){
            jPanelFavs.remove(favButtons[i]);
        }
        favbtnsize = 0;
        AddDesktop();
        jPanelFavs.repaint();
        jPanelFavs.setVisible(false);
        jPanelFavs.setVisible(true);
    }

    public void doPop(MouseEvent e){
        if (e.isPopupTrigger()){
            jPopupMenu1.show(e.getComponent(),e.getX(),e.getY());
        }
    }

    public void doPopRemove(MouseEvent e){
        if (e.isPopupTrigger()){
            tcomp = e.getComponent();
            jPopupMenu2.show(e.getComponent(),e.getX(),e.getY());
        }
    }


    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = GBBMGMTApp.getApplication().getMainFrame();
            aboutBox = new GBBMGMTAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        GBBMGMTApp.getApplication().show(aboutBox);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTreeGBB = new javax.swing.JTree();
        jTextFieldInfo = new javax.swing.JTextField();
        jDesktopPane1 = new javax.swing.JDesktopPane();
        jInternalFrameFavs = new javax.swing.JInternalFrame();
        jScrollPaneFavs = new javax.swing.JScrollPane();
        jPanelFavs = new javax.swing.JPanel();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        jMenuSettings = new javax.swing.JMenu();
        jMenuItemPref = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        jButtonExit = new javax.swing.JButton();
        jPopupMenu1 = new javax.swing.JPopupMenu();
        jPopupMenu2 = new javax.swing.JPopupMenu();

        mainPanel.setName("mainPanel"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("GBB Mgmt");
        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Administration");
        javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("User Admin");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Vessel Setup");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Wearhouse Setup");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Cost Code");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Discount Code");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Sales");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Current Inventory");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Customer Data");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Sales Order Operations");
        javax.swing.tree.DefaultMutableTreeNode treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("New Sales Order");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Sales Order");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Tap Room Operations");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Tap Room Keg Sale");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Tap Room Movement");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Production");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Brewhouse");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Brew Notes");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Recipes");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Beers");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Cellaring");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Movement Log");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Tank Status");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Barrel Movement");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Inventory Control");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Keg Split");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Brewery Tools");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Movement History");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Ingredients");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Malt Information");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Hop Information");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Yeast Information");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Purchasing");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Vendor Information");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Inventory Control");
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Malt Inventory Verification");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("Hop Inventory Verification");
        treeNode3.add(treeNode4);
        treeNode4 = new javax.swing.tree.DefaultMutableTreeNode("General Inventory Verification");
        treeNode3.add(treeNode4);
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Inventory Information");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Trial Brew");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Purchase Order Records");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("Reports");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Overdue Sales Orders");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Sales Report");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Brewing Forcast Report");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Brewers Report Of Operations");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("Colorado Tax Report");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        jTreeGBB.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        jTreeGBB.setName("jTreeGBB"); // NOI18N
        jTreeGBB.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTreeGBBMouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTreeGBBMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jTreeGBBMouseReleased(evt);
            }
        });
        jTreeGBB.addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
            public void valueChanged(javax.swing.event.TreeSelectionEvent evt) {
                jTreeGBBValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(jTreeGBB);

        jTextFieldInfo.setEditable(false);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getResourceMap(GBBMGMTView.class);
        jTextFieldInfo.setText(resourceMap.getString("jTextFieldInfo.text")); // NOI18N
        jTextFieldInfo.setName("jTextFieldInfo"); // NOI18N

        jDesktopPane1.setName("jDesktopPane1"); // NOI18N

        jInternalFrameFavs.setIconifiable(true);
        jInternalFrameFavs.setMaximizable(true);
        jInternalFrameFavs.setResizable(true);
        jInternalFrameFavs.setTitle(resourceMap.getString("jInternalFrameFavs.title")); // NOI18N
        jInternalFrameFavs.setName("jInternalFrameFavs"); // NOI18N
        jInternalFrameFavs.setVisible(true);

        jScrollPaneFavs.setName("jScrollPaneFavs"); // NOI18N

        jPanelFavs.setName("jPanelFavs"); // NOI18N
        jPanelFavs.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jPanelFavsMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jPanelFavsMouseReleased(evt);
            }
        });
        jPanelFavs.setLayout(new java.awt.GridBagLayout());
        jScrollPaneFavs.setViewportView(jPanelFavs);

        javax.swing.GroupLayout jInternalFrameFavsLayout = new javax.swing.GroupLayout(jInternalFrameFavs.getContentPane());
        jInternalFrameFavs.getContentPane().setLayout(jInternalFrameFavsLayout);
        jInternalFrameFavsLayout.setHorizontalGroup(
            jInternalFrameFavsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneFavs, javax.swing.GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)
        );
        jInternalFrameFavsLayout.setVerticalGroup(
            jInternalFrameFavsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPaneFavs, javax.swing.GroupLayout.DEFAULT_SIZE, 255, Short.MAX_VALUE)
        );

        jInternalFrameFavs.setBounds(50, 10, 290, 290);
        jDesktopPane1.add(jInternalFrameFavs, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 612, Short.MAX_VALUE))
                    .addComponent(jTextFieldInfo, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 841, Short.MAX_VALUE))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE)
                    .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 419, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextFieldInfo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getActionMap(GBBMGMTView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        jMenuSettings.setText(resourceMap.getString("jMenuSettings.text")); // NOI18N
        jMenuSettings.setName("jMenuSettings"); // NOI18N

        jMenuItemPref.setAction(actionMap.get("showPrefBox")); // NOI18N
        jMenuItemPref.setText(resourceMap.getString("jMenuItemPref.text")); // NOI18N
        jMenuItemPref.setName("jMenuItemPref"); // NOI18N
        jMenuSettings.add(jMenuItemPref);

        jMenuItem1.setAction(actionMap.get("showToolsBox")); // NOI18N
        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        jMenuSettings.add(jMenuItem1);

        menuBar.add(jMenuSettings);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        jButtonExit.setAction(actionMap.get("quit")); // NOI18N
        jButtonExit.setText(resourceMap.getString("jButtonExit.text")); // NOI18N
        jButtonExit.setName("jButtonExit"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 861, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(statusMessageLabel)
                    .addComponent(jButtonExit))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 640, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(statusPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
                        .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(statusMessageLabel)
                            .addComponent(statusAnimationLabel)
                            .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(11, 11, 11))
                    .addGroup(statusPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonExit)
                        .addContainerGap())))
        );

        jPopupMenu1.setName("jPopupMenu1"); // NOI18N

        jPopupMenu2.setName("jPopupMenu2"); // NOI18N

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void jTreeGBBValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jTreeGBBValueChanged
        // TODO add your handling code here:
        Object node = jTreeGBB.getLastSelectedPathComponent();
        if (node == null) return; //Return if nothing is selected.
        String nodeInfo = Actions.ReturnInfo(node.toString());
        jTextFieldInfo.setText(nodeInfo);
    }//GEN-LAST:event_jTreeGBBValueChanged

    private void jTreeGBBMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTreeGBBMouseClicked
        // TODO add your handling code here:
        if (evt.getClickCount()==2){
            Object node = jTreeGBB.getLastSelectedPathComponent();
            if (node == null) return; //Return if nothing is selected.
            Actions.CallFunction(node.toString());
            //jTextAreaMain.setText(DBA.results);
        }
    }//GEN-LAST:event_jTreeGBBMouseClicked

    private void jTreeGBBMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTreeGBBMousePressed
        // TODO add your handling code here:
        doPop(evt);
    }//GEN-LAST:event_jTreeGBBMousePressed

    private void jTreeGBBMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTreeGBBMouseReleased
        // TODO add your handling code here:
        doPop(evt);
    }//GEN-LAST:event_jTreeGBBMouseReleased

    private void jPanelFavsMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelFavsMousePressed
        // TODO add your handling code here:
    }//GEN-LAST:event_jPanelFavsMousePressed

    private void jPanelFavsMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelFavsMouseReleased
        // TODO add your handling code here:
    }//GEN-LAST:event_jPanelFavsMouseReleased

    @Action
    public void showPrefBox() {
        PreferencesFrame newFrame = new PreferencesFrame();
        newFrame.pack();
        newFrame.setLocation(250,250);
        newFrame.setVisible(true);
        newFrame.autofill();
    }

    @Action
    public void showToolsBox() {
        ToolsFrame newFrame = new ToolsFrame();
        newFrame.pack();
        newFrame.setLocation(250,250);
        newFrame.setVisible(true);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonExit;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JInternalFrame jInternalFrameFavs;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItemPref;
    private javax.swing.JMenu jMenuSettings;
    private javax.swing.JPanel jPanelFavs;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JPopupMenu jPopupMenu2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPaneFavs;
    private javax.swing.JTextField jTextFieldInfo;
    private javax.swing.JTree jTreeGBB;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;
}
